package com.wuye.charge.service.impl;

import java.util.List;

import com.wuye.charge.domain.WyCost;
import com.wuye.charge.domain.vo.WyBalconyunithomeVo;
import com.wuye.charge.domain.vo.WyCommunityVo;
import com.wuye.charge.mapper.WyBalconyunithomeVoMapper;
import com.wuye.charge.mapper.WyCostMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.wuye.charge.mapper.WyCostAllocationMapper;
import com.wuye.charge.domain.WyCostAllocation;
import com.wuye.charge.service.IWyCostAllocationService;

/**
 * 费用分配Service业务层处理
 * 
 * @author lishuo
 * @date 2024-11-22
 */
@Service
public class WyCostAllocationServiceImpl implements IWyCostAllocationService 
{
    @Autowired
    private WyCostAllocationMapper wyCostAllocationMapper;
    @Autowired
    private WyBalconyunithomeVoMapper wyBalconyunithomeVoMapper;
    @Autowired
    private WyCostMapper wyCostMapper;


    /**
     * 查询费用分配
     * 
     * @param allocationId 费用分配主键
     * @return 费用分配
     */
    @Override
    public WyCostAllocation selectWyCostAllocationByAllocationId(Long allocationId)
    {
        return wyCostAllocationMapper.selectWyCostAllocationByAllocationId(allocationId);
    }

    /**
     * 查询费用分配列表
     * 
     * @param wyCostAllocation 费用分配
     * @return 费用分配
     */
    @Override
    public List<WyCostAllocation> selectWyCostAllocationList(WyCostAllocation wyCostAllocation)
    {
        List<WyCostAllocation> wyCostAllocations = wyCostAllocationMapper.selectWyCostAllocationList(wyCostAllocation);

        for (WyCostAllocation item : wyCostAllocations) {
            WyBalconyunithomeVo vo = new WyBalconyunithomeVo();
            vo.setId(item.getBalconyunithomeId());
            WyCommunityVo wyCommunityVo = wyBalconyunithomeVoMapper.selectWyCommunityVoById(item.getBalconyunithomeId());
            vo.setCommunityId(wyCommunityVo.getCommunityId());
            List<WyBalconyunithomeVo> wyBalconyunithomeVos = wyBalconyunithomeVoMapper.selectWyBalconyunithomeVoList(vo);
            if(!wyBalconyunithomeVos.isEmpty()){
                WyBalconyunithomeVo balconyunithomeVo = wyBalconyunithomeVos.get(0);
                balconyunithomeVo.setCommunityId(wyCommunityVo.getCommunityId());
                balconyunithomeVo.setCommunityName(wyCommunityVo.getCommunityName());
                item.setWyBalconyunithomeVo(balconyunithomeVo);
            }
            WyCost wyCost = wyCostMapper.selectWyCostByCostId(item.getCostId());
            item.setWyCost(wyCost);
        }
        return wyCostAllocations;
    }

    /**
     * 新增费用分配
     * 
     * @param wyCostAllocation 费用分配
     * @return 结果
     */
    @Override
    public int insertWyCostAllocation(WyCostAllocation wyCostAllocation)
    {
        return wyCostAllocationMapper.insertWyCostAllocation(wyCostAllocation);
    }


    /**
     * 修改费用分配
     * 
     * @param wyCostAllocation 费用分配
     * @return 结果
     */
    @Override
    public int updateWyCostAllocation(WyCostAllocation wyCostAllocation)
    {
        return wyCostAllocationMapper.updateWyCostAllocation(wyCostAllocation);
    }

    /**
     * 批量删除费用分配
     * 
     * @param allocationIds 需要删除的费用分配主键
     * @return 结果
     */
    @Override
    public int deleteWyCostAllocationByAllocationIds(Long[] allocationIds)
    {
        return wyCostAllocationMapper.deleteWyCostAllocationByAllocationIds(allocationIds);
    }

    /**
     * 删除费用分配信息
     * 
     * @param allocationId 费用分配主键
     * @return 结果
     */
    @Override
    public int deleteWyCostAllocationByAllocationId(Long allocationId)
    {
        return wyCostAllocationMapper.deleteWyCostAllocationByAllocationId(allocationId);
    }
}
